import axios from 'axios';
import qs from 'query-string';
import type { DescData } from '@arco-design/web-vue/es/descriptions/interface';
import { HttpResponse } from '@/api/interceptor';

export interface Blog {
  id: number;
  title: string;
  author: string;
  content: string;
  status: number;
  createdAt: number;
  updatedAt: number;
}

export interface BlogParams extends Partial<Blog> {
  page: number;
  limit: number;
}

export interface BlogListRes {
  items: Blog[];
  total: number;
}

export function queryBlogList(params: BlogParams) {
  return axios.get<BlogListRes>('/vblog/api/v1/blogs', {
    params,
    paramsSerializer: (obj) => {
      return qs.stringify(obj);
    },
  });
}

export function addBlog(data: any) {
  return axios.post<HttpResponse>('/vblog/api/v1/blogs', data);
}

export function delBlog(id: number) {
  return axios.delete<HttpResponse>(`/vblog/api/v1/blogs/${id}`);
}

export interface ServiceRecord {
  id: number;
  title: string;
  description: string;
  name?: string;
  actionType?: string;
  icon?: string;
  data?: DescData[];
  enable?: boolean;
  expires?: boolean;
}
export function queryInspectionList() {
  return axios.get('/api/list/quality-inspection');
}

export function queryTheServiceList() {
  return axios.get('/api/list/the-service');
}

export function queryRulesPresetList() {
  return axios.get('/api/list/rules-preset');
}
